import { AUTHORIZATION_FIELD, USER_INFO_FIELD } from '@/config/autoConfig';

// authorization
export const getAuthorization = () => sessionStorage.getItem(AUTHORIZATION_FIELD);
export const setAuthorization = (value) => sessionStorage.setItem(AUTHORIZATION_FIELD, value);
export const removeAuthorization = () => sessionStorage.removeItem(AUTHORIZATION_FIELD);

// userInfo
export const getUserInfo = () => {
  const userInfo = sessionStorage.getItem(USER_INFO_FIELD);
  return userInfo ? JSON.parse(userInfo) : null;
};

export const setUserInfo = (value) => sessionStorage.setItem(USER_INFO_FIELD, JSON.stringify(value));

export const removeUserInfo = () => sessionStorage.removeItem(USER_INFO_FIELD);

export const removeAllAuthFields = () => {
  removeAuthorization();
  removeUserInfo();
};
